package com.CMUBiS.Data;

import java.io.PrintWriter;

/**
 * This class creates the page header for the user
 * 
 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
 * @version 0.1
 * @since 0.1
 * @date 04/05/2011
 *
 */
//TODO: Andy: make the header change depending on if the user is logged in
//TODO: add CSS and JScript
public class Header {
	private static final String EMPTY = "";
	
	/**
	 * Writes the header to the passed output writer. The header will change depending on whether the user
	 * is logged in or not
	 * 
	 * @param out The output writer to write the header to
	 * @param title The title of the page we are making the header for
	 * @param userID The userID that may have to be passed in the links
	 * @param authToken The authToken that may have to be passed in the links
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public static void writeHeader(PrintWriter out, String title, String userID, String authToken){
		// Check is the username and authToken are present. It will change what the user's header is
		String userString = "";
		if(userID != null && !userID.equals(EMPTY))
			userString = "userID=" + userID;
		
		String authString = "";
		if(authToken != null && !authToken.equals(EMPTY))
			authString = "&authToken=" + authToken;
		
		// Write the HTML tags
		out.println("<HTML>");
		out.println("<HEAD><TITLE>" + title + "</TITLE></HEAD>");
		out.println("<BODY>");
		
		// Write the menue items
		out.write("<a href=\"./index?" + userString + authString + "\">Home</a>");
		out.write(" | <a href=\"./browsecategory?" + userString + authString + "\">Browse</a>");
		out.write(" | <a href=\"./sellitem?" + userString + authString + "\">Sell</a>");
		out.write(" | <a href=\"./myaccount?" + userString + authString + "\">My Account</a>");
		out.write("<br /><br />");
	}
}
